home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16914 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  67 lines

  1. Path: news.ti.com!usenet
  2. From: Chuach@dlep1.itg.ti.com (Chua Chye Heng)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP!! How to correctly pass member functions to a C function???
  5. Date: Wed, 10 Apr 1996 01:19:51 GMT
  6. Organization: Texas Instruments
  7. Message-ID: <4kf534$csn@tilde.csc.ti.com>
  8. NNTP-Posting-Host: 137.167.42.30
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi,
  12.  
  13. I need to use a function in a c library which search some database and
  14. invoke the user defined function to process them in my c++ program.
  15.     /* c function prototype */
  16.     search( int (*norm_func)(), int (*err_func)());
  17.  
  18. My class definitions are as follows:
  19. extern "C" {
  20. #include "C-function.h"
  21. }
  22.  
  23. class base {
  24. ...
  25. public:
  26.     int process();
  27.     virtual int good_handle( data* pData ) = 0;
  28.     virtual int bad_handle( char* msg )=0;
  29. }
  30.  
  31. class derived : public base {
  32. ...
  33. public:
  34.     int good_handle( data* pData );
  35.     int bad_handle( char* msg);
  36. }
  37.  
  38. I use the process method in the base class to invoke the C function
  39. like this:
  40.     search ( (int(*)())this->good_handle, (int(*)())this->bad_handle);
  41.  
  42. When the program executes, the good_handle method in the derived class
  43. did get called. BUT the data* pData points to some "&^%$#" instead!!
  44. I did try to use a normal C program to test out the library and it is
  45. working fine.
  46.  
  47. Can some kind people help me out of this?? My project schedule is
  48. falling on me..... HELP
  49.  
  50. Deeply appreciate any hints or help..
  51.  
  52. BTW, I also try to use a normal C function to wrap around the two
  53. method but it also fail
  54.     base* pBase;
  55.     int good( ...) { pBase->good_handle(...); }
  56.     int bad(...) { pBase->bad_handle(...); }
  57.         and called them in process as: 
  58.         search (good_handle, bad_handle);
  59.  
  60.  
  61. ===========================================================
  62. Chye Heng
  63. Email: Chuach@dlep1.itg.ti.com
  64. Voice: 065-2902460
  65.  
  66.  
  67.